home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0486.arc
/
DUMP.C
< prev
next >
Wrap
Text File
|
1986-04-06
|
2KB
|
48 lines
/* file: DUMP.C
A dump utility that dumps bytes in the "right" order.
*/
#include "stdio.h"
main(argc,argv)
int argc;
char *argv[];
{
unsigned char buf[18]; /*input line of 16 bytes*/
FILE *in; /*input file descriptor*/
int i=0; /*loop counter*/
long int addrs=0; /*current position in file*/
buf[16]=0; /*force 17th byte to zero for string output*/
if ((in=fopen(argv[1],"rb")) == 0) /*try to open user file*/
{
fprintf(stderr,"Can't open input file: %s\n",argv[1]);
exit(1);
}
if (argc > 2) /*if there is a 2nd argument,*/
{
sscanf(argv[2],"%lx",&addrs); /*assume it is a*/
fseek(in,addrs,0); /*hex starting address*/
}
while (fread(buf,1,16,in) > 0) /*dump until end of file*/
{
if ((addrs & 511) == 0) /*print a header now and again*/
{
printf("\014\n\n\n\t\tDump of file %s\n",argv[1]);
printf("\t\t\t\t\t<--------: address:-------->\n");
}
for (i=15;i>=0;i--) /*loop for each 16 bytes to dump*/
{
printf(" %02x",buf[i]); /*print it in hex*/
if (buf[i]<32) /*if it is a control character,*/
buf[i]='<'; /*print as a less than sign*/
if (buf[i]>127) /*if it is del or has a sign bit*/
buf[i]='>'; /*print as a greater than sign*/
}
printf(" : %06X : %s\n",addrs,buf); /*print address and ascii*/
addrs += 16L; /*bump to next address*/
for (i=0;i<16;i++) /*to fill last line correctly,*/
buf[i]= 'Z' & 0x1f; /*init buffer to control-Z's*/
}
exit(0);
}